package com.sos.controller;

import com.sos.model.dto.*;
import com.sos.model.entity.HelperInfo;
import com.sos.model.vo.ResultVO;
import com.sos.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;

@RestController
@RequestMapping("/users")
@RequiredArgsConstructor
@Tag(name = "用户管理", description = "用户相关接口")
@SecurityRequirement(name = "bearerAuth")
@Slf4j
public class UserController {

    private final UserService userService;

    @PutMapping("/profile")
    @Operation(summary = "更新用户基本信息", description = "更新用户基本信息（除status字段外）")
    public ResultVO<?> updateUserInfo(@RequestBody UserUpdateDTO userUpdateDTO) {
        return userService.updateUserInfo(userUpdateDTO);
    }
    
    @PutMapping("/password")
    @Operation(summary = "更新用户密码", description = "更新用户密码")
    public ResultVO<?> updatePassword(@Valid @RequestBody PasswordUpdateDTO passwordUpdateDTO) {
        return userService.updatePassword(passwordUpdateDTO);
    }
    
    @PutMapping("/helper-status")
    @Operation(summary = "更新帮助他人状态", description = "更新用户是否愿意帮助他人的状态")
    public ResultVO<?> updateHelperStatus(@Valid @RequestBody HelperStatusUpdateDTO helperStatusUpdateDTO) {
        log.info("更新帮助他人状态");
        return userService.updateHelperStatus(helperStatusUpdateDTO);
    }
    
    @GetMapping("/profile")
    @Operation(summary = "获取当前用户基本信息", description = "获取当前用户的基本信息")
    public ResultVO<UserDetailDTO> getCurrentUserDetail() {
        log.info("获取当前用户基本信息");
        return userService.getCurrentUserDetail();
    }
    
    @GetMapping("/helper-status")
    @Operation(summary = "获取当前用户志愿者状态", description = "获取当前用户是否愿意成为志愿者的状态")
    public ResultVO<UserHelperStatusDTO> getCurrentUserHelperStatus() {
        log.info("获取当前用户志愿者状态");
        return userService.getCurrentUserHelperStatus();
    }

    @GetMapping("/online-status")
    @Operation(summary = "获取在线状态", description = "获取当前用户的在线状态和位置信息")
    public ResultVO<HelperInfo> getUserOnlineStatus() {
        return userService.getUserOnlineStatus();
    }

}